package com.ruoyi.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comment.domain.ResOpusComment;
import com.ruoyi.comment.service.IResOpusCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品评论Controller
 * 
 * @author ruoyi
 * @date 2021-12-20
 */
@RestController
@RequestMapping("/comment/opus")
public class ResOpusCommentController extends BaseController
{
    @Autowired
    private IResOpusCommentService resOpusCommentService;

    /**
     * 查询作品评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:opus:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResOpusComment resOpusComment)
    {
        startPage();
        List<ResOpusComment> list = resOpusCommentService.selectResOpusCommentList(resOpusComment);
        return getDataTable(list);
    }

    /**
     * 用户查询作品评论列表
     */
    @GetMapping("/userViewList")
    public TableDataInfo userViewList(ResOpusComment resOpusComment)
    {
        startPage();
        List<ResOpusComment> list = resOpusCommentService.selectResOpusCommentTreeList(resOpusComment);
        return getDataTable(list);
    }


    /**
     * 用户查询作品评论列表
     */
    @GetMapping("/viewList")
    public TableDataInfo viewList(ResOpusComment resOpusComment)
    {
        startPage();
        resOpusComment.setUserId(getUserId());
        List<ResOpusComment> list = resOpusCommentService.selectResOpusCommentViewList(resOpusComment);
        return getDataTable(list);
    }

    /**
     * 导出作品评论列表
     */
    @PreAuthorize("@ss.hasPermi('comment:opus:export')")
    @Log(title = "作品评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResOpusComment resOpusComment)
    {
        List<ResOpusComment> list = resOpusCommentService.selectResOpusCommentList(resOpusComment);
        ExcelUtil<ResOpusComment> util = new ExcelUtil<ResOpusComment>(ResOpusComment.class);
        util.exportExcel(response, list, "作品评论数据");
    }

    /**
     * 获取作品评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:opus:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(resOpusCommentService.selectResOpusCommentById(id));
    }

    /**
     * 新增作品评论
     */
    @Log(title = "作品评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResOpusComment resOpusComment)
    {
        resOpusComment.setUserId(getUserId());
        if(resOpusCommentService.insertResOpusComment(resOpusComment)==1){
            return toAjax(resOpusCommentService.updateResOpusComment(resOpusComment));
        }else{
            return toAjax(0);
        }
    }

    /**
     * 修改作品评论
     */
    @PreAuthorize("@ss.hasPermi('comment:opus:edit')")
    @Log(title = "作品评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResOpusComment resOpusComment)
    {
        return toAjax(resOpusCommentService.updateResOpusComment(resOpusComment));
    }

    /**
     * 修改作品评论(一键读取)
     */
    @PreAuthorize("@ss.hasPermi('comment:opus:edit')")
    @Log(title = "作品评论", businessType = BusinessType.UPDATE)
    @PutMapping("/modifyState/{ids}")
    public AjaxResult editState(@PathVariable Long[] ids)
    {
        return toAjax(resOpusCommentService.updateResOpusStatusComment(ids));
    }

    /**
     * 删除作品评论
     */
    @Log(title = "作品评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resOpusCommentService.deleteResOpusCommentByIds(ids));
    }
}
